/**
 * 
 */
package com.alianzamedica.controllers.reports;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.objectsearch.sqlsearch.ObjectSearch;
import org.objectsearch.web.tools.Converter;
import org.w3c.dom.Document;

import com.alianzamedica.businessobject.Doctor;
import com.alianzamedica.businessobject.MedicRecets;
import com.alianzamedica.connection.ConnectionImpl;
import com.alianzamedica.models.ReportModel;
import com.alianzamedica.tools.Enviroment;

/**
 * @author Carlos
 * 
 */
public class MedicPrescriptions extends Action {

	/*
	 * (non-Javadoc)
	 * 
	 * @seeorg.apache.struts.action.Action#execute(org.apache.struts.action.
	 * ActionMapping, org.apache.struts.action.ActionForm,
	 * javax.servlet.http.HttpServletRequest,
	 * javax.servlet.http.HttpServletResponse)
	 */
	@SuppressWarnings("unchecked")
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		Enviroment env = Enviroment.getInstance();
		Document doc = env.getDocument();
		ConnectionImpl impl = new ConnectionImpl();
		ObjectSearch search = new ObjectSearch(doc, impl);
		Doctor d = new Doctor();
		ArrayList<Doctor> medics = search.searchObjects(d);
		request.setAttribute("medics", medics);
		Integer id = Converter.string2Integer(request.getParameter("id"));
		if (id != null) {
			ReportModel model = new ReportModel();
			ArrayList<MedicRecets> recets = model.getRecets(id);
			request.setAttribute("recets", recets);
		}
		return mapping.findForward("success");
	}

}
